version 18.0               // version control
set processors 8           // to ensure replicability across different numbers of cores
clear all                  // clear existing data
macro drop _all            // and macros, clean slate
set seed 20220823          // set seed

*-------------------------------------------------------
* project: daylight saving time (dst)
*-------------------------------------------------------

local pgm  "dst-data02_acs_combine"  // file name
local who  "Muzhe Yang"              // author
local dte  "2022-08-23"              // created date
local dte2 "`c(current_date)'"       // last run date
local tag  "`pgm'.do, created by `who' on `dte', last run on `dte2'"

capture log close
log using "code\management\\`pgm'.txt", replace text
display "`tag'"

use "data_clean\acs\dst-data01_acs_pop_and_housing_basics_clean", clear
merge 1:1 GEOID using "data_clean\acs\dst-data01_acs_educ_attainment_clean"
drop _merge
merge 1:1 GEOID using "data_clean\acs\dst-data01_acs_marital_status_clean"
drop _merge
merge 1:1 GEOID using "data_clean\acs\dst-data01_acs_hh_size_clean"
drop _merge
merge 1:1 GEOID using "data_clean\acs\dst-data01_acs_health_ins_coverage_clean"
drop _merge
merge 1:1 GEOID using "data_clean\acs\dst-data01_acs_employ_status_clean"
drop _merge

replace pop               = pop/1000
gen double pop_density    = pop/area_land
replace hh_income_median  = hh_income_median/1000
replace home_value_median = home_value_median/1000

label variable pop               "total population (census tract), in 1000" 
label variable pop_density       "population density = total population/area of land, in 1000"
label variable hh_income_median  "median household income in the past 12 months, in $1000"
label variable home_value_median "median home value (for owner-occupied housing units), in $1000"

order educ_hs educ_coll educ_hs_pct educ_coll_pct married married_pct hh_size, after(age_median)
order area_land area_water area_shape, before(pop)
order pop_density, after(pop)
sort GEOID
codebook, compact
compress
save "data_clean\acs\\`pgm'.dta", replace 

log close
exit